import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

const mutations = {
    add(state,sum) {
        state.sum+=sum
    },
    SUB(state,sum){
        state.sum-=sum
    },
    ODD(state,sum){
        state.sum+=sum
    }
}

const actions = {
    add(context,value){
        context.commit('add',value)
    },
    odd(context,value){
        console.log(context,value)
        if(state.sum%2){
            context.commit('ODD',value)
        }
    }
}

const state = {
    sum:0
}
export default new Vuex.Store({
    mutations,
    actions,
    state
})
